package com.example.smartcity_40.Outpatient.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.smartcity_40.Outpatient.HospitaldetailsActivity;
import com.example.smartcity_40.Outpatient.bean.MediclistBean;
import com.example.smartcity_40.R;
import com.example.smartcity_40.tool.Tool;

import java.util.List;

public class MediclistApter extends  RecyclerView.Adapter<MediclistApter.Myhot> {

    private Context context;
    private List<MediclistBean.RowsBean> list;

    public MediclistApter(Context context) {
        this.context = context;
    }

    public void setDate(List<MediclistBean.RowsBean> list){
        this.list = list;
    }
    @NonNull
    @Override
    public MediclistApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.l_item_hospitallist, null);
        return new MediclistApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull MediclistApter.Myhot holder, int position) {
        try {
            String imgUrl = list.get(position).getImgUrl();
            if(!TextUtils.isEmpty(imgUrl)){
                Glide.with(context).load(Tool.url+imgUrl).into(holder.imgUrl);
            }

            String serviceName = list.get(position).getHospitalName();
            if(!TextUtils.isEmpty(serviceName)){
                holder.hospitalName.setText(serviceName);
            }
            int id = list.get(position).getLevel();
            holder.level.setText("星级 "+String.valueOf(id));

            holder.relayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent integer = new Intent(context, HospitaldetailsActivity.class);
                    integer.putExtra("hospitalid",String.valueOf(list.get(position).getId()));
                   context.startActivity(integer);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView level;
        private final TextView hospitalName;
        private final ImageView imgUrl;
        private final RelativeLayout relayout;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            imgUrl = itemView.findViewById(R.id.imgUrl);
            level = itemView.findViewById(R.id.level);
            hospitalName = itemView.findViewById(R.id.hospitalName);
            relayout = itemView.findViewById(R.id.relayout);
        }
    }
}

